from django.db import models


# Create your models here.
class DingBots(models.Model):
    name = models.CharField(verbose_name='机器人名称', max_length=20)
    to_group = models.CharField(verbose_name='接收群组', max_length=100)
    access_token = models.CharField(verbose_name='授权码', max_length=100)
    is_active = models.BooleanField(verbose_name='开启推送', default=True)
    create_at = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    modify_at = models.DateTimeField(verbose_name='修改时间', auto_now=True)
    scenes = models.ManyToManyField('Scenes', verbose_name='推送场景')
    creator = models.CharField(default='admin', max_length=20, verbose_name='创建者')


class Scenes(models.Model):
    type = {
        ('Text', 'Text类型'),
        ('Link', 'Link类型'),
        ('MarkDown', 'MarkDown类型'),
        ('ActionCard', 'ActionCard类型'),
        ('FeedCard', 'FeedCard类型'),
        ('SingleTarget', 'SingleTarget类型'),
    }
    name = models.CharField(verbose_name='场景名称', max_length=20)
    msg_type = models.CharField(verbose_name='消息类型', max_length=20, choices=type)
    context_id = models.TextField()
    is_active = models.BooleanField(verbose_name='生效', default=True)
    at_once = models.BooleanField(verbose_name='立即发送', default=False)
    sent_number = models.PositiveIntegerField(verbose_name='重复次数', default=0,)  # 用户设置的发送次数
    sent_count = models.PositiveIntegerField(verbose_name='已发送次数', default=0)
    # timers = models.ForeignKey('Timers', default=0,blank=True, verbose_name='定时发送', related_name='timers',
    # on_delete=models.CASCADE)
    at_moblies = models.TextField(verbose_name='指定人员')
    is_atall = models.BooleanField(verbose_name='指定全员', default=False)
    create_at = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    modify_at = models.DateTimeField(verbose_name='修改时间', auto_now=True)
    creator = models.CharField(default='admin', max_length=20, verbose_name='创建者')

    def __unicode__(self):
        return self.name

    def __str__(self):
        return self.name

# class Contents(models.Model):
#     text = models.TextField()
#     title = models.TextField()
#     picUrl = models.TextField()
#     messageUrl = models.TextField()
#     hideAvatar = models.TextField()
#     btnOrientation = models.TextField()
#     singleTitle = models.TextField()
#     singleURL = models.TextField()
#     btns = models.TextField()
#     create_at = models.DateField()
#     modify_at = models.DateField()


class Timers(models.Model):
    week = {
        ('Sun','星期日'),
        ('Mon','星期一'),
        ('Tue','星期二'),
        ('Wed','星期三'),
        ('Thu','星期四'),
        ('Fri','星期五'),
        ('Sat','星期六'),
    }
    scenes = models.ForeignKey(Scenes,  on_delete=models.CASCADE)
    timer_type = models.CharField(max_length=20,verbose_name='定时器类型')
    interval = models.PositiveIntegerField(verbose_name='时间间隔')
    year = models.DateTimeField()
    month = models.PositiveIntegerField()
    minute = models.PositiveIntegerField()
    weekly = models.CharField(verbose_name='每周', max_length=20,choices=week)
    start_at = models.DateTimeField(verbose_name='开始时间')
    end_at = models.DateTimeField(verbose_name='结束时间')
    create_at = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)
    modify_at = models.DateTimeField(verbose_name='修改时间', auto_now=True)
